package joSaysHello.shared.entity;

import java.io.Serializable;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "false")
public class User implements Serializable
{
	private static final long serialVersionUID = -1820703091873455178L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String encodedKey;
	
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
	private String userId;
	
	@Persistent
	private String nickname;
	
	@Persistent(mappedBy = "who")
	transient
	private List<Hello> hellos = null;
	
	public User(String userId, String nickname) {
		super();
		this.userId = userId;
		this.nickname = nickname;
	}
	@SuppressWarnings("unused")
	private User()
	{}
	
	public String getEncodedKey()
	{
		return encodedKey;
	}
	public String getUserId() {
		return userId;
	}
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	public List<Hello> getHellos() {
		return hellos;
	}
	
	@Override
	public String toString() {
		return this.getNickname();
	}
	public String printFull() {
		return encodedKey+" "+userId+" "+nickname+" "+(hellos == null ? "null" : hellos.size());
	}
	
}
